export const isPhone = (Tel) => {
  var re=new RegExp(/^((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)$/);
  if (!Tel) {
    return false;
  }
  var retu=Tel.match(re);
 if(retu){
     return true;
 }else{
     return false;
 }
}

export const validateClient = (client, babies) => {
  let errors = {babies:{}}
  for(let cproperty in client) {
    let propertyValue = client[cproperty]
    if(cproperty === 'phone' && !isPhone(propertyValue)) {
      errors[cproperty] = true
    }

    if(cproperty === 'mobile_num' && !isPhone(propertyValue)) {
      errors[cproperty] = true
    }

    // console.log('client[cproperty]', cproperty, propertyVspan eeeeeealue)
    if(typeof propertyValue !== 'number' && !propertyValue ) {
      errors[cproperty] = true
    }
  }

  babies.forEach((baby, index) => {
    for(let bbproperty in baby) {
      if(typeof baby[bbproperty] !== 'number' && !baby[bbproperty]) {
        if(typeof errors.babies[index] === 'undefined') errors.babies[index] = {}
        errors.babies[index][bbproperty] = true
      }
    }
  })

  console.debug('JSON.stringify(errors)', JSON.stringify(errors), JSON.stringify(babies))
  return errors
}
